﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

using PLCS.Domain;
using PLCS.Domain.Orders;
using PLCS.Domain.Stations;

using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.DependencyInjection;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;

namespace PLCS.EntityFrameworkCore.EntityFrameworkCore;

[DependsOn(typeof(AbpAutofacModule))]
[DependsOn(typeof(AbpEntityFrameworkCoreModule))]
[DependsOn(typeof(PLCSDomainModule))]
[DependsOn(typeof(AbpAuditLoggingEntityFrameworkCoreModule))]
public class PLCSEntityFrameworkCoreModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAbpDbContext<PLCSDbContext>(opt =>
        {
            opt.AddDefaultRepositories(true);
        });
        Configure<AbpDbContextOptions>(opt =>
        {
            opt.UseSqlServer();
        });
        Configure<AbpEntityOptions>(options =>
        {
            options.Entity<Station>(orderOptions =>
            {
                orderOptions.DefaultWithDetailsFunc = query => query.Include(o => o.Trays);
            });
        });
    }
}